package com.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.ChannelBean;
import com.project.bean.MainPostBean;
import com.project.bean.UserBean;
import com.project.service.IMainPostService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDate;

@RestController
@RequestMapping("mainPost")
public class MainPostController {
    @Autowired
    private IMainPostService mainPostService;

    @RequestMapping("cutFindByItem")
    public IPage<MainPostBean> cutFindByItem(Integer pageNum,Integer channelID,String title,
                                            String userName,LocalDate startDate,LocalDate endDate){
        return mainPostService.cutFindByItem(pageNum,channelID,title,userName,startDate,endDate);
    }
    @RequestMapping("add")
    public String add(String title, String content, Integer channelID, HttpServletRequest request){
        UserBean userBean = (UserBean) request.getSession().getAttribute("loginUser");
        MainPostBean mainPostBean = new MainPostBean(title,content, userBean.getId(), channelID);
        mainPostService.add(mainPostBean);
        return "ok";
    }
    @RequestMapping("findById")
    public MainPostBean findById(Integer id){
        return mainPostService.findByID(id);
    }
}
